define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'share/reward/index' + location.search,
                    add_url: 'share/reward/add',
                    edit_url: 'share/reward/edit',
                    order_url: 'recharge/index',//跳转到用户列表
                    del_url: 'share/reward/del',
                    multi_url: 'share/reward/multi',
                    import_url: 'share/reward/import',
                    sync_url: 'share/reward/statistics',
                    table: 'share_reward',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'mutual_money', title: __('互助金'), operate:false},
                        {field: 'user_flags', title: __('User_flags')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'status', title: __('发放状态'), searchList: {"0":__('未发放'),"1":__('已发放')}, formatter: Table.api.formatter.status},
                        {field: 'type', title: __('Type'), searchList: {"1":__('推广员日创收'),"2":__('代言人日创收'),"3":__('一星网店主周创收'),"4":__('一星网店主日创收'),"5":__('二星网店主日创收'),"7":__('推广员日创收'),"8":__('创客日创收'),"9":__('网店店长日创收'),"10":__('网店店主日创收'),"11":__('一级经销商日创收'),"12":__('二级经销商日创收'),"13":__('三级经销商日创收')}, formatter: Table.api.formatter.status},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: '操作', table: table,
                            //events: Table.api.events.addtabs,
                            buttons: [
                                {
                                    name: 'shareuser',
                                    text: __('查看订单'),
                                    // icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    // url: 'recharge/index?id={order_id}',
                                    url: 'shopro/order/order/index?alert_order_id={order_id}',
                                    refresh: true,

                                    visible:function(row){
                                        if((1==1)){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }

                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        statistics: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    sync_url: 'share/reward/statistics',
                    table: 'share_reward_statistics',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.sync_url,
                pk: 'id',
                sortName: 'id',
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: true,
                columns: [
                    [
                        {field: 'title', title:'', operate:false},
                        {field: 'money', title: '', operate:false},
                        {field: 'addtime', title: __('时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible:false},
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        sync: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
